import request from '@/utils/request.js';

//  创建工单
export async function omsnCreate(data = {}) {
  return await request.post('/oms/oms/omsn/create/ajax', data);
}

//  我的工单
export async function omsmFind(data = {}) {
  return await request.post('/oms/oms/omsm/find/ajax', data);
}

//  待我转派
export async function omstFind(data = {}) {
  return await request.post('/oms/oms/omst/find/ajax', data);
}

//  转派工单
export async function omsmTransfer(data = {}) {
  return await request.post('/oms/oms/omsm/transfer/ajax', data);
}

//  待我处理
export async function omshFind(data = {}) {
  return await request.post('/oms/oms/omsh/find/ajax', data);
}

//  处理工单
export async function omshHandle(data = {}) {
  return await request.post('/oms/oms/omsh/handle/ajax', data);
}

//  待我结单
export async function omscFind(data = {}) {
  return await request.post('/oms/oms/omsc/find/ajax', data);
}

//  结单工单
export async function omscClose(data = {}) {
  return await request.post('/oms/oms/omsc/close/ajax', data);
}

const VITE_API_BASE_URL = import.meta.env.VITE_API_BASE_URL;
//  单点登录， //加密字符串
export async function singleLogin(parameter = '') {
  console.log('singleLogin', parameter);
  const response = await fetch(VITE_API_BASE_URL + '/oms/singleLogin', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'   // 常见写法；若用 FormData 可省略
    },
    body: JSON.stringify({ parameter })             // 把对象转成 JSON 字符串
  });

  if (!response.ok) {                     // HTTP 状态码不是 2xx
    throw new Error(`HTTP error! status: ${response.status}`);
  }
  return response.json();                 // 按 JSON 解析返回值
}


//  判断当前是否有新的数据
export async function hasNewData(data) {
  return await request.post('oms/set/resc/get', data);
}